package com.cryptoneedle.center.source.entity;

import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.center.common.key.TableKey;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;

/**
 * <p>description: Doris-元数据-Table </p>
 * <p>
 * 整合参考：
 * 1.SHOW TABLE STATUS FROM internal.xxx; 主要
 * 2.SHOW FULL TABLES FROM internal.xxx; 补充
 * 2.SELECT * FROM information_schema.tables; 不同步
 *
 * @author CryptoNeedle
 * @date 2025-09-25
 */
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "doris_table")
@IdClass(TableKey.class)
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@Comment("Doris-Table")
public class DorisTable extends BaseEntity {

    @Id
    @Column(length = 512)
    @Comment("所属 Catalog")
    private String catalogName;

    @Id
    @Column(length = 64)
    @Comment("所属 Database")
    private String databaseName;

    @Id
    @Column(length = 64)
    @Comment("表名称")
    private String tableName;

    @Column(length = 64)
    @Comment("表类型，包括：SYSTEM VIEW、VIEW、BASE TABLE")
    private String tableType;

    @Comment("存储格式")
    private String storageFormat;

    @Comment("倒排索引存储格式")
    private String invertedIndexStorageFormat;

    @Column(length = 64)
    @Comment("表引擎类型")
    private String engine;

    //@Comment("无效值")
    //private Long version;

    //@Column(length = 10)
    //@Comment("无效值")
    //private String rowFormat;

    @Comment("表预估行数")
    private Long tableRows;

    @Comment("表平均行大小")
    private Long avgRowLength;

    @Comment("表预估大小")
    private Long dataLength;

    //@Comment("无效值")
    //private Long maxDataLength;

    //@Comment("无效值")
    //private Long indexLength;

    //@Comment("无效值")
    //private Long dataFree;

    //@Comment("无效值")
    //private Long autoIncrement;

    @Comment("表创建时间")
    private Date createTime;

    @Comment("表数据更新时间")
    private Date updateTime;

    //@Comment("无效值")
    //private Date checkTime;

    @Column(length = 32)
    @Comment("固定值：utf-8")
    private String tableCollation;

    //@Comment("无效值")
    //private Long checksum;

    //@Column(length = 255)
    //@Comment("无效值")
    //private String createOptions;

    @Column(length = 2048)
    @Comment("表注释")
    private String tableComment;

    public TableKey getKey() {
        return new TableKey(this.catalogName, this.databaseName, this.tableName);
    }

    public String getKeyString() {
        return getKey().toString();
    }
}